#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : POS_api_test_project 
@File    : get_headers.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/5/28 9:04 
@Describe: 获取POS请求头
"""
from Config.setting import ConfigHandler
from Utils.timesUtils.timeControl import get_timestamp
from Utils.redisUtils.redisControl import RedisHandler
from Utils.readFilesUtils.yamlControl import GetYamlData


def get_headers() -> dict:
    """获取POS请求头"""
    brandCode = str(GetYamlData(ConfigHandler.CONFIG_PATH).get_yaml_data()['brandCode'])
    environment = GetYamlData(ConfigHandler.CONFIG_PATH).get_yaml_data()['environment']
    timestamp = str(get_timestamp())
    redis = RedisHandler()
    token = redis.get_redis_value(environment + '-pos-token-' + brandCode)  # 取出redisPOS请求token
    loginMac = redis.get_redis_value(environment + '-loginMac-' + brandCode)  # 取出redisPOS请求设备mac
    headers = {
        'Connection': 'keep-alive',
        'retry_count': '1',
        'x-http-timestamp': timestamp,
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) ??POS?????/1.0.22 Chrome/87.0.4280.60 Electron/11.0.1 Safari/537.36',
        'retry': '4',
        'Accept': '*/*',
        'x-http-token': token,
        'x-http-osversion': '1.0.22',
        'x-http-request-id': loginMac + '-' + timestamp,
        'Accept-Language': 'zh-CN',
        'Cookie': 'SERVERID=k8s-ingress.gtmsh.com:10080; x-http-token=' + token,
        'Content-Type': 'application/json'
    }
    return headers
